<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="scenicSpot"/>
    <#include "../common/header.ftl">
</head>
<body>
<#--景点的页面-->
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">景点管理</h1>
                </div>
            </div>
        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/scenicSpot/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入景点名字/城市">
                </div>
                <button class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>景点</th>
                    <th>封面</th>
                    <th>所属城市</th>
                    <th>门票价格</th>
                    <th>主题</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.scenicSpotName}</td>
                        <td><img src="${(entity.coverUrl)!}" width="100"></td>
                        <td>${entity.region.name}</td>
                        <td>${(entity.ticket.price)!}</td>
                        <td>${(entity.theme.themeName)!}</td>
                        <td>

                            <a role="button" class="btn btn-info btn-xs inputBtn" data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/scenicSpot/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">景点名称</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="scenicSpotName"/>
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-lg-4 control-label">所属城市</label>
                        <div class="col-lg-6">
                            <select name="region.id" class="form-control">
                                <#list regions as region>
                                    <option value="${region.id}">${region.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-lg-4 control-label">门票价格</label>
                        <div class="col-lg-6">
                            <input type="number" class="form-control" name="ticket.price"/>
                            <input type="hidden" class="form-control" name="ticket.id" />
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-lg-4 control-label">主题</label>
                        <div class="col-lg-6">
                            <select name="theme.id" class="form-control">
                                <#list themes as theme>
                                    <option value="${theme.id}">
                                        ${theme.themeName}
                                    </option>
                                </#list>
                            </select>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {

        $(".inputBtn").click(function () {

            $("#editForm input").val("");
            $("#editForm select").val("").removeAttr("disabled").css("background-color","white");
            var json = $(this).data("json");
            if (json) {
                $("#editForm select[name='region.id']").attr("disabled", true).css("background-color","#C0C0C0");
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='scenicSpotName']").val(json.scenicSpotName);
                $("#editForm select[name='region.id']").val(json.regionId);
                $("#editForm input[name='ticket.price']").val(json.price);
                $("#editForm input[name='ticket.id']").val(json.ticketId);
                $("#coverUrl").attr("src", json.coverUrl);
                $("#editForm select[name='theme.id']").val(json.themeId);
            }
            $("#inputModal").modal("show");
        });

        $(".submitBtn").click(function () {
            $("#editForm select").removeAttr("disabled");
            $("#editForm").submit();
        });
    });
</script>
</body>
</html>